﻿using System;
using System.Collections.Generic;

namespace FirstFloor.Documents.Extensions
{
    internal class AnonymousObservable<T>
        : IObservable<T>
    {
        private Func<IObserver<T>, IDisposable> subscribeAction;

        /// <summary>
        /// Initializes a new instance of the <see cref="AnonymousObservable&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="subscribeAction">The subscribe action.</param>
        public AnonymousObservable(Func<IObserver<T>, IDisposable> subscribeAction)
        {
            this.subscribeAction = subscribeAction;
        }

        /// <summary>
        /// Subscribes to specified observer.
        /// </summary>
        /// <param name="observer">The observer.</param>
        /// <returns></returns>
        public IDisposable Subscribe(IObserver<T> observer)
        {
            return subscribeAction(observer);
        }
    }
}
